<template>
    <div>
<!--      <el-table-->
<!--        ref="queryTable"-->
<!--        :data="tableData"-->
<!--        :fit="true"-->
<!--        height="300px"-->
<!--        v-loading="load"-->
<!--      >-->
<!--        <el-table-column-->
<!--          v-for="(col,index) in columns"-->
<!--          :key="col.id"-->
<!--          :label="col.name"-->
<!--          :min-width="col.minWidth"-->
<!--          :width="col.width"-->
<!--          :prop="col.code"-->
<!--          :align="col.align"-->
<!--          :sortable="col.sortable"-->
<!--          header-align="left"-->
<!--          show-overflow-tooltip>-->
<!--          <template slot-scope="scope">-->
<!--            <template v-if="col.code === 'xh'">-->
<!--              {{scope.$index + 1}}-->
<!--            </template>-->
<!--            <template v-else-if="col.click">-->
<!--              <span @click="showApprove(scope.row)" style="color: #00afff;cursor: pointer;"> {{ scope.row[scope.column.property] }} </span>-->
<!--            </template>-->
<!--            <template v-else-if="type === 1 && col.code === 'sfyxc'">-->
<!--              <span v-if="scope.row.sfyxc==='1'"><el-tag type="warning">待安排</el-tag></span>-->
<!--              <span v-else-if="scope.row.sfyxc==='2'"><el-tag type="warning">已安排待下场</el-tag></span>-->
<!--              <span v-else-if="scope.row.sfyxc==='3'"><el-tag type="success">已下场</el-tag></span>-->
<!--            </template>-->
<!--            <template v-else-if="type === 3 && col.code === 'sfykfp'">-->
<!--              <el-tag v-if="scope.row.sfykfp === 'Y'" type="success">是</el-tag>-->
<!--              <el-tag v-else type="warning">否</el-tag>-->
<!--            </template>-->
<!--            <template v-else-if="type === 4 && col.code === 'kdgs'">-->
<!--              <span v-if="scope.row.kdgs === 'sf'">顺丰</span>-->
<!--              <span v-if="scope.row.kdgs === 'jd'">京东</span>-->
<!--              <span v-if="scope.row.kdgs === 'yt'">圆通</span>-->
<!--              <span v-if="scope.row.kdgs === 'zt'">中通</span>-->
<!--            </template>-->
<!--            <template v-else-if="type === 4 && col.code === 'yjsp'">-->
<!--              <span v-if="scope.row.yjsp === '1'">仪器</span>-->
<!--              <span v-if="scope.row.yjsp === '2'">证书</span>-->
<!--              <span v-if="scope.row.yjsp === '3'">文件</span>-->
<!--              <span v-if="scope.row.yjsp === '4'">标签</span>-->
<!--              <span v-if="scope.row.yjsp === '5'">合同</span>-->
<!--              <span v-if="scope.row.yjsp === '6'">其他</span>-->
<!--            </template>-->
<!--            <template v-else>-->
<!--              {{ scope.row[scope.column.property] }}-->
<!--            </template>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--          <template slot-scope="scope">-->

<!--            <div v-if="type === 1">-->
<!--              <el-button-->
<!--                v-if="scope.row.jcfs === '1'"-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-s-custom"-->
<!--                @click="apxcUser(scope.row)"-->
<!--              >下场</el-button>-->

<!--              <el-button-->
<!--                v-if="scope.row.jcfs === '1'"-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-tickets"-->
<!--                @click="finalLog(scope.row)"-->
<!--              >下场日志</el-button>-->
<!--            </div>-->

<!--            <div v-if="type === 3">-->

<!--              <el-button-->
<!--                v-if="scope.row.sfykfp==='Y'"-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-notebook-2"-->
<!--                @click="invoice(scope.row, 2)"-->
<!--              >未开发票</el-button>-->

<!--              <el-button-->
<!--                v-else-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-notebook-2"-->
<!--                @click="invoice(scope.row, 1)"-->
<!--              >开发票</el-button>-->

<!--              <el-button-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-s-finance"-->
<!--                @click="returnMoney(scope.row)"-->
<!--              >回款</el-button>-->

<!--              <el-button-->
<!--                size="mini"-->
<!--                type="text"-->
<!--                icon="el-icon-tickets"-->
<!--                @click="returnMoneyLog(scope.row)"-->
<!--              >回款记录</el-button>-->
<!--            </div>-->

<!--          </template>-->

<!--        </el-table-column>-->
<!--      </el-table>-->

      <!--  ========================================  下场安排开始  ==============================================    -->
      <!--   下场安排表单   -->
      <xcap-form v-if="showXcap" :showForm="showXcap" :title="xcapTitle" :formInfo="xcapForm" :ShowBtn="true" @close="cancel"></xcap-form>

      <!-- 选择下场人员 -->
      <xcForm
        v-if="showUserDialog"
        :showSelectUser="showUserDialog"
        :form="xcData"
        @close="closeUser"
      ></xcForm>

      <!-- 下场人员日志 -->
      <XcLogList v-if="showXcLog" :showXcLog="showXcLog" :logData="logData" @closeXcLog="closeXcLog"></XcLogList>

      <!--  ========================================  下场安排结束  ==============================================    -->

      <!--  ========================================  完工单安排开始  ==============================================    -->
      <!--   完工单安排表单   -->
      <wgd-form v-if="showWgd" :showForm="showWgd" :title="wgdTitle" :formInfo="wgdForm" :ShowBtn="true" @close="cancel"></wgd-form>

      <!-- 是否回款 -->
      <hk-form v-if="showHk" :show-hk="showHk" :formInfo="hkForm" @close="closeHk"></hk-form>

      <!-- 开发票 -->
      <KfpForm v-if="showKfp" :showKfp="showKfp" :formInfo="kfpData" @close="closeKfp"></KfpForm>

      <!-- 回款日志 -->
      <HkLogList v-if="showHkLog" :showXcLog="showHkLog" :logData="hkLogData" @closeHkLog="closeHkLog"></HkLogList>

      <!--  ========================================  完工单安排结束  ==============================================    -->
    </div>
</template>

<script>
import KfpForm from '@/views/gd/wgd/kfpForm.vue'
import HkLogList from '@/views/gd/wgd/hkLogList.vue'
import XcLogList from '@/views/gd/xcap/XcLogList.vue'
import XcapForm from '@/views/gd/xcap/formInfo.vue'
import xcForm from '@/views/gd/xcap/xcForm.vue'
import WgdForm from '@/views/gd/wgd/formInfo.vue'
import { getYwd } from '@/api/gd/ywd'
import { getWgd, updateWgd } from '@/api/gd/wgd'
import HkForm from '@/views/gd/wgd/HkForm.vue'
export default {
  name: 'CommonTable',
  components: { HkForm, XcapForm, WgdForm, xcForm, XcLogList, HkLogList, KfpForm},
  props: {
    tableData: {
      type: Array
    },
    columns: {
      type: Array
    },
    type: {
      type: Number
    },
    load: {
      type: Boolean
    }
  },
  data() {
    return {
      // 下场安排
      xcapForm: {},
      showXcap: false,
      xcapTitle: '',
      // 完工单
      wgdForm: {},
      showWgd: false,
      wgdTitle: '',
      // 下场安排
      showUserDialog: false,
      xcData: {},
      logData: [],
      hkLogData: [],
      showHkLog: false,
      showXcLog: false,
      showHk: false,
      showKfp: false,
      hkForm: {},
      showLog: false,
      kfpData: {}
    }
  },
  methods: {
    showApprove(row) {
      // type = 1 下场安排   type = 3 完工单
      if (this.type === 1) {
        this.getXcapData(row)
      }else if (this.type === 3) {
        this.getWgdData(row);
      }
    },
    closeKfp() {
      this.showKfp = false
      this.$emit('refresh')
    },
    invoice(row, item) {
      getWgd(row.id).then(res => {
        this.kfpData = res.data
        // 未开发票按钮
        if (item === 1) {
          this.showKfp = true
        }else {
          // 如果当前状态是已经开发票状态
          this.$modal.confirm("请确认是否要更改为：未开发票 状态").then(() => {
            this.loading = true;
            this.$set(this.kfpData, 'sfykfp', 'N')
            this.$set(this.kfpData, 'fpph', '')
            updateWgd(this.kfpData).then(response => {
              this.$modal.msgSuccess("已设置为：未开票状态！");
              this.loading = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
              this.$emit('refresh')
            });
          })
        }
      })

    },
    // 回款
    returnMoney(row) {
      this.hkForm = row
      this.showHk = true
    },
    closeHk() {
      this.showHk = false
      this.$emit('refresh')
    },
    // 回款日志
    returnMoneyLog(row) {
      this.hkLogData = row
      this.showHkLog = true
    },
    closeHkLog() {
      this.showHkLog = false
      this.$emit('refresh')
    },
    closeXcLog() {
      this.showXcLog = false
      this.$emit('refresh')
    },
    finalLog(row) {
      this.logData = row
      this.showXcLog = true
    },
    // 安排下场
    apxcUser(row) {
      this.xcData = row
      this.showUserDialog = true
    },
    closeUser() {
      this.xcData = {}
      this.showUserDialog = false
      this.$emit('refresh')
    },
    getXcapData(row) {
      if (row !== '' && row !== null) {
        getYwd(row.id).then(res => {
          this.xcapForm = res.data
          this.showXcap = true
          this.xcapTitle = "业务单信息";
        })
      }else {
        this.xcapForm = row
      }
    },
    cancel() {
      if (this.type === 1) {
        this.showXcap = false
      }else if (this.type === 3) {
        this.showWgd = false
      }
      this.$emit('refresh')
    },
    getWgdData(row) {
      if (row !== '' && row !== null) {
        getWgd(row.id).then(response => {
          this.wgdForm = response.data
          this.showWgd = true
          this.wgdTitle = "业务单信息";
        })
      }else {
        this.wgdForm = row
      }

    },
    // 文件点击回调
    handlePreview(file) {
      let suffix = file.name.substring(file.name.lastIndexOf(".") + 1);
      if (suffix === 'pdf') {
        this.showPdf = true
        this.fjId = file.id
        this.fjTitle = "PDF预览"
      }else if (suffix === 'xlsx' || suffix === 'xls') {
        getFjById(file.id, 'blob').then(response => {
          const binaryData = [];
          binaryData.push(response);
          let url = window.URL.createObjectURL(new Blob(binaryData, { type: 'application/octet-stream' }));
          const link = document.createElement('a');
          link.href = url
          link.download = file.name;
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
        })
      }

    },
  }
}
</script>

<style scoped>

</style>
